﻿using System;
using System.Linq;
using System.Web.UI.WebControls;

namespace MONTRASEC_test.Classes
{
  public class UtilFillInTemplateOnSexualExploitationOfChildren
  {
    internal static void getInvitationToFillTemplateOnSexualExploitationOfChildren(BulletedList myBulletedList, String myID)
    {

      A_NEWENTRY_DataContext dataContext = new A_NEWENTRY_DataContext();
      var data = from c in dataContext.A_NEWENTRY_s
                 where c.ID == long.Parse(myID)
                 select new { c.B_1_EVENTS_SEXUALEXPLOITATION_SEXUALEXPLOITATION, c.B_2_VICTIM_PERSONALDATA_DATEOFBIRTH };




      //  "SELECT [B_1_EVENTS_SEXUALEXPLOITATION_SEXUALEXPLOITATION], [B_2_VICTIM_PERSONALDATA_DATEOFBIRTH] FROM A_NEWENTRY_ Where ID=@ID";

      foreach (var c in data)
      {
        if (c.B_2_VICTIM_PERSONALDATA_DATEOFBIRTH.HasValue)
        {
          DateTime comparisonDate = new DateTime(((DateTime)c.B_2_VICTIM_PERSONALDATA_DATEOFBIRTH).Year, DateTime.Now.Month, DateTime.Now.Day);



          int age = (comparisonDate.Date < ((DateTime)c.B_2_VICTIM_PERSONALDATA_DATEOFBIRTH).Date) ?
          DateTime.Now.Year - ((DateTime)c.B_2_VICTIM_PERSONALDATA_DATEOFBIRTH).Year - 1 :
          DateTime.Now.Year - ((DateTime)c.B_2_VICTIM_PERSONALDATA_DATEOFBIRTH).Year;


          if ((c.B_1_EVENTS_SEXUALEXPLOITATION_SEXUALEXPLOITATION == true) && (age < 18))
          {
            myBulletedList.Items.Add("there is a sexual exploitation and the victim is below 18 years of age, please fill in the template on sexual exploitation of children.");
          }
        }
      }
   
    }
  }
}
